﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class D_LiveStock_Mix
    {
        public bool CreateOneLiveStock_Mix(LiveStock_Mix_Info objLiveStock_Mix_Info)
        {
            CommonDAL objCommonDAL = new CommonDAL();
            SqlConnection objConnection = objCommonDAL.GetConnection();
            SqlCommand command = new SqlCommand("LiveStock_Mix_Insert", objConnection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter(@"MixID", objLiveStock_Mix_Info.MixID));
            command.Parameters.Add(new SqlParameter(@"LivestockID", objLiveStock_Mix_Info.LivestockID));
            bool isOk = false;
            try
            {
                objConnection.Open();
                int k = command.ExecuteNonQuery();
                if (k > 0)
                    isOk = true;
            }
            catch (System.Exception ex)
            {
                isOk = false;
            }
            finally
            {
                objConnection.Close();
            }
            return isOk;
        }
        //**********************************************************************************       
        public bool EditOneLiveStock_Mix(LiveStock_Mix_Info objLiveStock_Mix_Info)
        {
            CommonDAL objCommonDAL = new CommonDAL();
            SqlConnection objConnection = objCommonDAL.GetConnection();
            SqlCommand command = new SqlCommand("LiveStock_Mix_Update", objConnection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@MixID", objLiveStock_Mix_Info.MixID));
            command.Parameters.Add(new SqlParameter("@LivestockID", objLiveStock_Mix_Info.LivestockID));
            bool isOk = false;
            try
            {
                objConnection.Open();
                int k = command.ExecuteNonQuery();
                if (k > 0)
                    isOk = true;
            }
            catch (System.Exception ex)
            {
                isOk = false;
            }
            finally
            {
                objConnection.Close();
            }
            return isOk;
        }
        //******************************************************************************       
        public bool RemoveOneLiveStock_Mix(int MixID)
        {
            CommonDAL objCommonDAL = new CommonDAL();
            SqlConnection objConnection = objCommonDAL.GetConnection();
            SqlCommand command = new SqlCommand("LiveStock_Mix_Delete", objConnection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter(@"MixID", MixID));
            bool isOk = false;
            try
            {
                objConnection.Open();
                int k = command.ExecuteNonQuery();
                if (k > 0)
                    isOk = true;
            }
            catch (System.Exception ex)
            {
                isOk = false;
            }
            finally
            {
                objConnection.Close();
            }
            return isOk;
        }
        //******************************************************************************       
        public DataTable GetAllLiveStock_Mix()
        {
            DataSet ds = new DataSet();
            CommonDAL objCommonDAL = new CommonDAL();
            SqlConnection objConnection = objCommonDAL.GetConnection();
            SqlCommand command = new SqlCommand("LiveStock_Mix_SelectAll", objConnection);
            command.CommandType = CommandType.StoredProcedure;
            try
            {
                objConnection.Open();
                SqlDataAdapter da = new SqlDataAdapter(command);
                da.Fill(ds);
            }
            catch (System.Exception ex)
            {
                return null;
            }
            finally
            {
                objConnection.Close();
            }
            return ds.Tables[0];
        }
        //******************************************************************************       
        public LiveStock_Mix_Info GetOneLiveStock_Mix(int MixID)
        {
            LiveStock_Mix_Info objLiveStock_Mix_Info = new LiveStock_Mix_Info();
            CommonDAL objCommonDAL = new CommonDAL();
            SqlConnection objConnection = objCommonDAL.GetConnection();
            SqlCommand command = new SqlCommand("LiveStock_Mix_SelectByID", objConnection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter(@"MixID", MixID));
            try
            {
                objConnection.Open();
                SqlDataReader ordLiveStock_Mix = command.ExecuteReader(); //OjectRecordDatareader
                ordLiveStock_Mix.Read();
                if (ordLiveStock_Mix.HasRows)
                {
                    if (ordLiveStock_Mix["MixID"] != DBNull.Value)
                    {
                        objLiveStock_Mix_Info.MixID = Convert.ToInt16(ordLiveStock_Mix["MixID"]);
                    }
                    if (ordLiveStock_Mix["LivestockID"] != DBNull.Value)
                    {
                        objLiveStock_Mix_Info.LivestockID = Convert.ToInt16(ordLiveStock_Mix["LivestockID"]);
                    }
                }
            }
            catch (System.Exception ex)
            {
                return null;
            }
            finally
            {
                objConnection.Close();
            }
            return objLiveStock_Mix_Info;
        }
    }
}
